package jianzhiOffer;

public class num42 {
    public int maxSubArray(int[] nums) {
        int prev = nums[0];
        int max = nums[0];
        for(int i = 1;i < nums.length;i ++) {
            prev = Math.max(prev + nums[i],nums[i]);
            max = Math.max(prev,max);
        }
        return max;
    }
}
